using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class UserControls_Admin_EditProductAdmin : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {

            pNameTextBox.Text = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Name;
            pPriceTextBox.Text = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Price.ToString("0");
            catalogPromotionCheckBox.Checked = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).OnCatalogPromotion;
            departmentPromotionCheckBox.Checked = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).OnDepartmentPromotion;
            // lista z producentami
            brandDropDownList.DataSource = CatalogAccess.GetBrands();
            brandDropDownList.DataBind();
            //brandDropDownList.SelectedItem.Text = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).BrandName;
            brandDropDownList.SelectedItem.Text = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).BrandName;
            onBasketCheckBox.Checked = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Basket;

            //brandDropDownList.Items.Insert(0, " - Wybierz Producenta - ");
        }


        departmentLabel.Text = CatalogAccess.GetDepartmentDetails(Request.QueryString["DepartmentID"]).Name;
        categoryLabel.Text = CatalogAccess.GetCategoryDetails(Request.QueryString["CategoryID"]).Name;
        statusLabel.ForeColor = System.Drawing.Color.Red;
        
    }

    protected void goBackLink_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.ApplicationPath + "/Admin/ProductsAdmin.aspx?DepartmentID=" + Request.QueryString["DepartmentID"]
           + "&CategoryID=" + Request.QueryString["CategoryID"]);

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string name = pNameTextBox.Text.ToString();
        string des = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Description;
        string price = pPriceTextBox.Text.ToString();
        string image1 = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Image1FileName;
        string image2 = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Image2FileName;
        string catP = catalogPromotionCheckBox.Checked.ToString();
        string depP = departmentPromotionCheckBox.Checked.ToString();
        string brandid = brandDropDownList.SelectedItem.Value;
        string bask = onBasketCheckBox.Checked.ToString();


        string categoryid = Request.QueryString["ProductID"];
        bool success = CatalogAccess.UpdateProduct(categoryid, name, des, price, image1, image2, catP, depP, brandid, bask);

        statusLabel.Text = success ? "Aktualizacja udana" : "Aktualizacja nieudana";


    }
}
